﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DnPakExplorer.Controls;
using TextDesignerCSLibrary;

namespace DnPakExplorer.Forms {
	public partial class AppellationForm : FormBase {
		public AppellationForm() {
			InitializeComponent();
			SetStyle(ControlStyles.ResizeRedraw, true);
			AppellationAdapter adapter = new AppellationAdapter();
			listGridView1.SetAdapter(adapter);
		}

		private void listGridView1_MouseDoubleClick(object sender, MouseEventArgs e) {
			if (e.Button == System.Windows.Forms.MouseButtons.Left) {
				Point index = listGridView1.PointToCellIndex(e.Location);
				if (index.X>=0 && index.Y>=0) {
					Character ch = DnPlayerUtil.CurrentCharacter;
					Appellation app = new Appellation();
					app.AppellationId = index.Y;
					ch.Appellation = app;
					MessageBox.Show("已应用称号能力。");
				}
			}
		}

		class AppellationAdapter : ListGridAdapter {
			Dntable mTable;

			public AppellationAdapter() {
				mTable = DnResourceUtil.Appellationtable;
			}

			public override void OnDrawGrid(ListGridView view, Graphics g, string text, Color color, int row, int column, Rectangle rect) {
				if (column == 0) {
					string inColorString = (string)mTable[row, 27];
					string outColorString = (string)mTable[row, 28];
					if (!string.IsNullOrEmpty(inColorString) && !string.IsNullOrEmpty(outColorString)) {
						DrawingUtil.DrawOuterGrowText(g, rect, text, view.Font.FontFamily, view.Font.Style, view.Font.SizeInPoints*1.25f,
							 ColorTranslator.FromHtml(inColorString), Color.FromArgb(50, ColorTranslator.FromHtml(outColorString)), 1, 1.4f, view.StringFormat);
						return;
					}

				}

				base.OnDrawGrid(view, g, text, color, row, column, rect);
			}

			public override int RowCount {
				get { return mTable.RecordCount; }
			}

			public override int ColumnCount {
				get { return 3; }
			}

			public override void GetTopLeft(Grid drid) {
				drid.text = "";
			}

			public override void GetGridData(int row, int column, Grid grid) {
				switch (column) {
				case 0:
					grid.text = Util.FindUIString((int)mTable[row, 0]);
					grid.textColor = ColorTranslator.FromHtml((string)mTable[row, 25]);
					if (grid.text == null) {
						grid.text = "";
					}
					break;
				case 1:
					grid.text = mTable[row, 1].ToString();
					break;
				case 2:
					grid.text = Util.FindUIString((int)mTable[row, 2]);
					if (grid.text == null) {
						grid.text = "";
					}
					break;
				}

			}

			public override void GetRowHeader(int row, Grid grid) {
				grid.text = mTable.GetKey(row).ToString();
			}

			public override void GetColumnHeader(int column, Grid grid) {
				switch (column) {
				case 0:
					grid.text = "名称";
					break;
				case 1:
					grid.text = "等级限制";
					break;
				case 2:
					grid.text = "描述";
					break;
				}
			}


			


		}
	}
}
